package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Paper;
import edu.hwadee.service.PaperService;

public class PaperServiceImpl extends BasicServiceImpl implements PaperService {

	@Override
	public boolean save(Paper paper) {
		try {
			getPaperDAO().save(paper);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Paper paper) {
		try {
			getPaperDAO().delete(paper);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Paper> search(Paper paper) {
		try {
			return (List<Paper>)getPaperDAO().findByExample(paper);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Paper searchById(Integer paperId) {
		try {
			return getPaperDAO().findById(paperId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Paper paper) {
		try {
			if(searchById(paper.getPaperId()) != null) {
				getPaperDAO().merge(paper);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Paper> showAll() {
		try {
			return (List<Paper>)getPaperDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
